package com.heiyu.utils;

import com.alibaba.fastjson.JSON;
import com.heiyu.dao.ArticleMarkMapper;
import com.heiyu.entity.ArticleMark;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class MarkInfoUtils {

    @Autowired
    private ArticleMarkMapper articleMarkMapper;
    @Autowired
    private RedisUtils redisUtils;

    public ArticleMark getMarkName(Long markId){
       String str = null;//redisUtils.get(CacheKey.ARTICLE_MARK_INFO+markId);
       ArticleMark mark = null;
       if(!StringUtils.isEmpty(str)){
            mark = JSON.parseObject(str,ArticleMark.class);
       }else{
           mark = articleMarkMapper.selectPrimary(markId);
           if(mark != null){
               redisUtils.set(CacheKey.ARTICLE_MARK_INFO+mark.getId(),JSON.toJSONString(mark));
           }
       }
       return mark;
    }

}
